#! /bin/bash --debug

declare -r BASEDIR="$(dirname ${0})";

source "${BASEDIR}/scripts/generic.sh";

setCwdToMyDir;
assertFileExists "scripts/update_templates.sh";

AUTORECONF="$(which autoreconf)";
if [ -z "${AUTORECONF}" -o ! -x "${AUTORECONF}" ];
then                                                   
  logError "Please install GNU Auto(conf|make)";  \
else                                              \
  AUTORECONF_VERSION="$(${AUTORECONF} --version | \
      awk '{ print $0; exit 0; }')";              \
  logInfo "Found ${AUTORECONF_VERSION}";          \
fi;

logInfo "Updating templated files...";
"scripts/update_templates.sh" 1>autogen.err 2>&1;
checkReturnCode "Error(s)! Check autogen.err for details." true;

export WARNINGS="-Werror -Wgnu -Wportability -Wunsupported -Woverride \
    -Wsyntax -Wcross";

logInfo "Running autoreconf...";
"${AUTORECONF}" --install --force 1>autogen.err 2>&1;
checkReturnCode "Error(s)! Check autogen.err for details." true;

# Cleanup
rm -rf "lc_config.h.in~" "autom4te.cache" "autogen.err";

